package com.weixing.mall.provider.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weixing.mall.provider.mapper.CategoryBrandMapper;
import com.weixing.mall.provider.model.domain.CategoryBrand;
import com.weixing.mall.provider.model.dto.CategoryBrandDelDto;
import com.weixing.mall.provider.model.dto.CategoryBrandDto;
import com.weixing.mall.provider.model.dto.CategoryBrandListDto;
import com.weixing.mall.provider.model.query.CategoryBrandQuery;
import com.weixing.mall.provider.model.vo.CategoryBrandVo;
import com.weixing.mall.provider.service.ICategoryBrandService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName CategoryBrandServiceImpl
 * @Description TODO <br/>
 * @Author gjq
 * @Modified By:
 * @Date 2019/8/6
 * @Version 1.0
 **/
/**
 * <p>
 * 商品模块-商品类目品牌关联表 服务实现类
 * </p>
 *
 * @author Small
 * @since 2019-11-20
 */
@Service
public class CategoryBrandServiceImpl extends ServiceImpl<CategoryBrandMapper, CategoryBrand> implements ICategoryBrandService {

    @Override
    public void save(CategoryBrandListDto categoryBrandListDto) {
        CategoryBrand categoryBrand = new CategoryBrand();
        long ategoryId = categoryBrandListDto.getCategoryId();
        for(int i=0;i<categoryBrandListDto.getBrandIds().length;i++){
            CategoryBrandDto categoryBrandDto = new CategoryBrandDto();
            categoryBrandDto.setCategoryId(ategoryId);
            categoryBrandDto.setBrandId(categoryBrandListDto.getBrandIds()[i]);
            BeanUtils.copyProperties(categoryBrandDto,categoryBrand);
            save(categoryBrand);
        }

    }

    @Override
    public List<CategoryBrandVo> selectList(CategoryBrandQuery categoryBrandQuery) {
        return baseMapper.selectList(categoryBrandQuery);
    }

    @Override
    public void deleteByIds(CategoryBrandDelDto categoryBrandDelDto) {
        long categoryId = categoryBrandDelDto.getCategoryId();
        long[] ids = categoryBrandDelDto.getIds();
        baseMapper.deleteByIds(categoryId,ids);
    }
}
